﻿// CheckModelNewDialog.cpp: 实现文件
//

#include "stdafx.h"
#include "zChecker.h"
#include "CheckModelNewDialog.h"
#include "afxdialogex.h"


// CCheckModelNewDialog 对话框

IMPLEMENT_DYNAMIC(CCheckModelNewDialog, CDialogEx)

CCheckModelNewDialog::CCheckModelNewDialog(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_CHECK_MODEL_NEW, pParent)
	, m_strModelName(_T(""))
	, m_strProductName(_T(""))
{

}

CCheckModelNewDialog::~CCheckModelNewDialog()
{
}

void CCheckModelNewDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_MODEL_NAME, m_strModelName);
	DDX_Control(pDX, IDC_COMBO_PRODUCT, m_cmbProduct);
	DDX_CBString(pDX, IDC_COMBO_PRODUCT, m_strProductName);
}


BEGIN_MESSAGE_MAP(CCheckModelNewDialog, CDialogEx)
	ON_BN_CLICKED(IDOK, &CCheckModelNewDialog::OnBnClickedOk)
END_MESSAGE_MAP()


// CCheckModelNewDialog 消息处理程序


BOOL CCheckModelNewDialog::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	ck::DataProductManager* pProductManager = NULL;
	pProductManager = ck::DataProductManager::GetInstance();

	ck::DataProductInfo* pProduct = NULL;
	z_uint32 nCount = pProductManager->GetCount();
	int nItem = 0;

	m_cmbProduct.Clear();

	for (z_uint32 i = 0; i < nCount; i++)
	{
		pProduct = pProductManager->GetDataProduct(i);
		nItem = m_cmbProduct.AddString(pProduct->GetName());
		m_cmbProduct.SetItemData(nItem, (DWORD)pProduct->GetCode());
	}
	if (m_cmbProduct.GetCount() > 0)
	{
		m_cmbProduct.SetCurSel(0);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CCheckModelNewDialog::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码

	UpdateData(TRUE);

	ck::CheckModel* pModel = NULL;
	ck::CheckModelManager* pModelManager = ck::CheckModelManager::GetInstance();

	//z_uint32	code,
	//	const char* szCode,
	//	const char* szName,
	//	z_uint32	productCode,
	//	const char* szProduct,
	//	const char* szDscription

	z_uint32 code = 1;
	CString strCode = "";
	z_uint32 nProductCode = m_cmbProduct.GetItemData(m_cmbProduct.GetCurSel());
	CString strDescription = "";

	RESULTCODE rc = pModelManager->CreateModel(code, strCode, m_strModelName, nProductCode, m_strProductName, strDescription);
	if (rc != RC_SUCCESS)
	{
		return;
	}

	AfxMessageBox("成功创建检查模型");

	CDialogEx::OnOK();
}
